<include file="OrderFood:header" />
<?php
/*
 *	通过菜品的分值进行配置, 有菜品分类值，方便未来扩展
 *	首先menu.js中页面加载完执行判断orignum的数量，进行模拟点击事件操作
 */
?>
<script type="text/javascript">
var maxOrderNum = {:C('ORDER_MAX')};	// 用户可点菜数，当前默认是7，未来这里可以在后台配置,16_11_23修改
</script>
<script type="text/javascript" src="__PUBLIC__/js/scroller.js"></script>
<!-- 模拟针对菜品初始化的操作 -->
<script type="text/javascript" src="__PUBLIC__/js/menu.js"></script>
<!-- 针对+/-、checkbox的click事件的处理 -->
<script type="text/javascript" src="__PUBLIC__/js/main.js"></script>
<!--script type="text/javascript" src="__PUBLIC__/js/light7.js"></script-->
<!-- 新增的样式-->

<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/alert.css">
<link rel="stylesheet" type="text/css" href="__PUBLIC__/css/order-index.css">
<style type="text/css">
.share_bg {
  -webkit-tap-highlight-color: transparent;
  outline: 0 none;
  text-decoration: none;

  margin: 0px;
  padding: 0px;
  color: #333333;
  font: 14px Microsoft YaHei;
  font-family: "Microsoft YaHei";
  line-height: 20px;

  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.7);
  z-index: 9696969;
}
</style>
<body onselectstart="return true;" ondragstart="return false;">
<div class="container">
	<div id="muhead">
		<div id="head-background">
			<!--img id="header-background-image" src="__PUBLIC__/images/header-background_01.jpg"-->
			<img id="header-background-image" src="https://img.yzcdn.cn/upload_files/2015/07/09/FrWLc31WQcdNyIUAHP7k5I_thofQ.jpg">
			<div id="mu-nav">
			</div>
			<div id="mu-menu">
				<span style="padding: 0% 1.5%;"></span>
				<img id="mu-logo" src="__PUBLIC__/images/9mu-logo-02.png">
				<!--img src="https://img.yzcdn.cn/upload_files/2015/07/09/Fk1GU7hK59H9cPnNfd1WMoTnaQgh.jpg?imageView2/2/w/200/h/200/q/75/format/jpg" style="width: 72px; height: 72px;"-->
				<span class="mu-menu-list">
					<ul class="mu-menu-ul">
						<li class="zmenu">{$today}</li>
						<li class="zemnu img"><img src="__PUBLIC__/images/seprate.png"></li>
						<li class="zmenu">菜篮子:<span id="basketid">{$basketid}</span></li>
						<li class="zemnu img"><img src="__PUBLIC__/images/seprate.png"></li>
						<li class="zmenu"><a href="{:U('Wap/OrderFood/myOrder')}">我的订单</a></li>
					</ul>
				</span>
			</div>
		</div>
		
	</div>
	<if condition="($collnames|count) neq 1">
	<div>
		<header class="nav menu" id="nav2">
			<div>
				<volist name="collnames" id="col">
				<a href1="javascript:;" onclick="" class="colname <if condition="$colName eq $col['colname']">on</if>" colname="{$col['colname']}" colmoney="{$col['colmoney']}">{$col['colname']}套餐</a>
				</volist>
			</div>
		</header>
	</div>
	<else />
		<volist name="collnames" id="col">
		<input type="hidden" class="colname" colname="{$col['colname']}" colmoney="{$col['colname']}">
		</volist>
	</if>
	<div id="mucontent">
	<form name="cart_form" action="{:U('OrderFood/sureOrder',array('openid' => $openid))}" method="post">
		<input type="hidden" value="{$colName}" name="colName" id="colName">
		<input type="hidden" value="{$colMoneyTotal}" name="colMoneyTotal" id="colMoneyTotal">
		<section class="menu_wrap" id="menuWrap">
			<if condition="foods neq null">
				<div class="menu_container" id="mymenu_lists">
					<!-- 输出套餐区 -->
					<div class1="menu_tt nodztj_c" class="menu_tt1" data-type="{$sfoods['sort']['id']}"><h2>套餐区</h2></div>
					<!-- 1.循环套餐-->
					<volist name="foods" id="cfoods">
					<div class="colfoods" colname="{$key}" curcolname="{$colName}" style="<if condition="$colName eq $key">display:block;<else/>display:none;</if>">
					<!-- 2.循环分类-->
					<volist name="cfoods" id="sfoods" key="k2">
						<!--div class="menu_tt nodztj_c" data-type="{$sfoods['sort']['id']}"><h2>{$sfoods['sort']['name']}</h2></div-->
						<ul class="menu_list nodztj_c">
							<!-- 3.循环分类里的菜品-->
							<volist name="sfoods['foods']" id="food" key="k3">
							<li class="fgroup{$food['fgroup']}">
								<div>
									<if condition="$food neq null">
									<img src="{$food['image']}" alt="" url="{$food['image']}">
									</if>
								</div>
								<div>
									<h3>{$food['foodname']}</h3>
									<p class="salenum"></p>
									<div class="info">{$food['des']|htmlspecialchars_decode=ENT_QUOTES}</div>
								</div>
								<div class="price_wrap">
									<!--div class="fr" max="{$food['instock']}">
										<a href="javascript:void(0);" class="btn add"></a>
									</div-->
									<!-- 增加class order-num,来判断初始循环defchoose -->
									<div class="fr order-num" <if condition="$kconoff eq 1"> max="{$food['instock']}" <else/>max="-1"</if> type="{$food['type']}" fid="{$food['foodid']}" name="{$food['foodname']}" data-sort="{$sfoods['sort']['id']}" data-price="{$food['price']}" data-ftype="colfood" data-unit="<if condition="$food['unit'] neq null">{$food['unit']}<else/>份</if>" data-num="{$food['orignum']}" data-fgroup="{$food['fgroup']}">
										<!--span style="display:inline;">
											<a href="javascript:void(0);" class="btn del active"></a>
											<span class="num">1</span>
										</span-->
										<if condition="$kconoff eq 0 OR $food['instock'] gt 0">
										<!-- 设置初始数量 默认为0,如是修改,将显示为订单里的菜数量 -->
										<input type="checkbox" class="fcheck" name1="foods[colfood][{$food.foodid}][isChs]" name="foods[colfood][{$food.foodid}][num]"  <if condition="$food['orignum'] neq 0">checked="checked"</if> onclick111="onClickHander(this)" value="0">
										<input type="hidden" name="foods[colfood][{$food.foodid}][name]" value="{$food.foodname}">
										<input type="hidden" name="foods[colfood][{$food.foodid}][id]" value="{$food.foodid}">
										<input type="hidden" class="ftype" name="foods[colfood][{$food.foodid}][ftype]" value="colfood">
										<!--a href="javascript:void(0);" class="btn add" data-num="{$food['orignum']}"></a-->
										</if>
									</div>
									<!--input autocomplete="off" class="number" type="hidden" name="foods[{$food['id']}]" value=""-->
								</div>
							</li>
							</volist>
						</ul>
					</volist>
					</div>
					</volist>
					<!-- 输出备选区的菜品 -->
					<div class1="menu_tt nodztj_c" class="menu_tt1" data-type="{$sfoods['sort']['id']}"><h2>备选区</h2></div>
					<volist name="opFoods" id="sfoods" key="k2">
						<!--div class="menu_tt nodztj_c" data-type="{$sfoods['sort']['id']}"><h2>{$sfoods['sort']['name']}</h2></div-->
						<ul class="menu_list nodztj_c">
							<volist name="sfoods['foods']" id="food" key="k3">
							<li>
								<div>
									<if condition="$food neq null">
									<img src="{$food['image']}" alt="" url="{$food['image']}">
									</if>
								</div>
								<div>
									<h3>{$food['foodname']}</h3>
									<p class="salenum"><!--月售<span class="sale_num">{$food['m_sale']}</span><span class="theunit"><if condition="$food['unit'] neq null">{$food['unit']}<else/>份</if></span>-->
									<span>
									<if condition="$kconoff eq 1"> 库存：{$food['instock']}</if>
									</span>
							<!--<span class="sales"><strong class="sale_8"></strong></span>--></p>
									<div class="info">{$food['des']|htmlspecialchars_decode=ENT_QUOTES}</div>
								</div>
								<div class="price_wrap">
									<!-- 依据九亩的需求，去掉价格 -->
									<!--strong style="font-size:1em;">价格:<span class="unit_price">{$food['price']}</span></strong-->
									<!-- 增加class order-num,来判断初始循环defchoose -->
									<div class="fr order-num" <if condition="$kconoff eq 1"> max="{$food['instock']}" <else/>max="-1"</if> type="{$food['type']}" fid="{$food['foodid']}" name="{$food['foodname']}" data-defchs="{$food['defchoose']}" data-reqchs="{$food['reqchoose']}" data-credit="{$food['cicredit']}" data-sort="{$sfoods['sort']['id']}" data-price="{$food['price']}" data-ftype="opfood" data-unit="<if condition="$food['unit'] neq null">{$food['unit']}<else/>份</if>" data-num="{$food['orignum']}" data-limitnum="{$food['limit_num']}">
										<if condition="$kconoff eq 0 OR $food['instock'] gt 0">
										<!-- 设置初始数量 默认为0,如是修改,将显示为订单里的菜数量 -->
										<a href="javascript:void(0);" class="btn add" data-num="{$food['orignum']}"></a>
										</if>
									</div>
									<input autocomplete="off" class="number" type="hidden" name="foods[opfood][{$food.foodid}][num]" value="0">
									<input type="hidden" name="foods[opfood][{$food.foodid}][name]" value="{$food.foodname}">
									<input type="hidden" name="foods[opfood][{$food.foodid}][id]" value="{$food.foodid}">
									<input autocomplete="off" class="ftype" type="hidden" name="foods[opfood][{$food.foodid}][ftype]" value="opfood">
								</div>
							</li>
							</volist>
						</ul>
					</volist>
					<!--输出另购区-->
					<div class1="menu_tt nodztj_c" class="menu_tt1" data-type="{$sfoods['sort']['id']}"><h2>另购区</h2></div>
					<volist name="plusFoods" id="sfoods" key="k2">
						<ul class="menu_list nodztj_c">
							<volist name="sfoods['foods']" id="food" key="k3">
							<li>
								<div>
									<if condition="$food neq null">
									<img src="{$food['image']}" alt="" url="{$food['image']}">
									</if>
								</div>
								<div>
									<h3>{$food['foodname']}</h3>
									<p class="salenum"><!--月售<span class="sale_num">{$food['m_sale']}</span--><span class="theunit"><if condition="$food['unit'] neq null">{$food['unit']}<else/>份</if></span>
									<span>
									<!--<if condition="$kconoff eq 1"> 库存：{$food['instock']}</if>-->
									</span>
									</p>
									<div class="info">{$food['des']|htmlspecialchars_decode=ENT_QUOTES}</div>
								</div>
								<div class="price_wrap">
									<strong style="font-size:1em;color: rgb(211,193,173);">价格:<span class="unit_price">{$food['price']}</span></strong>
									<!--div class="fr" max="{$food['instock']}">
										<a href="javascript:void(0);" class="btn add"></a>
									</div-->
									<!-- 注释:
										增加class order-num,来判断初始循环defchoose 
										初始化时，通过判断orignum大于0进行初始化模拟点击事件
									-->
									<div class="fr order-num" <if condition="$kconoff eq 1"> max="{$food['instock']}" <else/>max="-1"</if> type="{$food['type']}" fid="{$food['foodid']}" name="{$food['foodname']}" data-defchs="{$food['defchoose']}" data-reqchs="{$food['reqchoose']}" data-credit="{$food['cicredit']}" data-sort="{$sfoods['sort']['id']}" data-price="{$food['price']}" data-ftype="plusfood" data-unit="<if condition="$food['unit'] neq null">{$food['unit']}<else/>份</if>" data-num="{$food['orignum']}" unit="{$food['unit']}">
										<if condition="$kconoff eq 0 OR $food['instock'] gt 0">
										<!-- 设置初始数量 默认为0,如是修改,将显示为订单里的菜数量 -->
										<a href="javascript:void(0);" class="btn add" data-num="{$food['orignum']}"></a>
										</if>
									</div>
									<input autocomplete="off" class="number" type="hidden" name="foods[plusfood][{$food.foodid}][num]" value="0">
									<input type="hidden" name="foods[plusfood][{$food.foodid}][name]" value="{$food.foodname}">
									<input type="hidden" name="foods[plusfood][{$food.foodid}][id]" value="{$food.foodid}">
									<input autocomplete="off" class="ftype" type="hidden" name="foods[plusfood][{$food.foodid}][ftype]" value="plusfood">
								</div>
							</li>
							</volist>
						</ul>
					</volist>
				</div>
			</if>
			<!--删除旧代码-->
			<!--div class="menu_container" id="mymenu_lists"-->
			<!--删除旧代码-->
			
		</section>
		<input type="hidden" name="orderid" value="{$orderid}">
		<footer class="shopping_cart">
			<div class="fixed row row-center">
				<!--span>样数:</span-->
				<div class="cart_bg">
					<span class="cart_num mu-color" id="cartNum"></span>
				</div>
				<div class="mu-color" style="font-size: 14px;">您需额外支付金额:￥<span id="extraPrice"></span></div>
				<div class="col"></div>
				<div>
					<span class="comm_btn disabled"><span id="sendCondition"></span></span>
					<a id="settlement" href1="javascript:document.cart_form.submit();" href="javascript:submitCheck();" class="comm_btn" style="display: none;background-color: rgb(121,45,0);">提交订单</a>
				</div>
			</div>
		</footer>
	</form>
	</div>
	<div class="menu_detail" id="menuDetail">
		<img style="display: none;">
		<div class="nopic"></div>
		<a href="javascript:void(0);" class="comm_btn" id="detailBtn">来一份</a>
		<!--dl style="display:none;">
			<dt>价格：</dt>
			<dd class="highlight">￥<span class="price"></span></dd>
		</dl>
		<p class="sale_desc">月售<span class="sale_num"></span>份</p-->
		<div>
			<h3 style="height:31px; line-height:31px; padding-top:5px; margin-bottom:5px;">介绍：</h3>
			<div class="info" style="line-height:20px;"></div>
		</div>
	</div>

</div>
<script type="text/javascript">
	var cancelOrderUrl = "{:U('Wap/OrderFood/cancelOrder')}";
	// 主要设置一些套餐的初始值,考虑了修改订单的情况
	var colCreditTotal = "{$colCreditTotal}";	// 套餐应有分值
	var colMoneyTotal = "{$colMoneyTotal}";		// 当前所属套餐的规定金额
	var orderColName = "{$colName}";
	
	var maxCount="{$maxCount}";
	var curMaxCount = 6;
	var colCreditCount = 0;						// 统计当前套餐的总分值
	var foodsCount = 0;							// 统计当前列表展示的菜的总数
	var foodsArr = new Array();					
	var orderid = {$orderid};
	var isExcess = false;
	var isHasColMoneyTotalFood = false;			// 是否套餐中拥有刚好等于套餐规定金额的菜品

	var vegTypeNumsArr = Array();				// 记录菜品种 数
	window.shareData = {  
		"moduleName":"OrderFood",
		"moduleID":"{$company['id']}",
		"imgUrl": "{$company['logourl']}", 
		"sendFriendLink": "{$f_siteUrl}{:U('DishOut/dishMenu',array('token' => $token,'cid'=>$cid))}",
		"tTitle": "{$metaTitle}",
		"tContent": "{$metaTitle}"
	 };
</script>
<script type="text/javascript">

$(function(){
	// 切换套餐相关元素的显示
	$(".colname").click(function(){
		var colname = $(this).attr('colname');
		var colmoney = $(this).attr('colmoney');
		if(orderColName != colname) {
			// 设置表单值
			orderColName = colname;
			$("#colName").val(colname);
			$("#orderColMoney").val(colmoney);
			// 切换到 对应的套餐div
			$(".colfoods[colname='"+colname+"']").css('display', 'block');
			$(".colfoods[colname!='"+colname+"']").css('display', 'none');
			$(this).addClass('on');
			$(this).siblings().removeClass('on');

			// 对foodsArr中的套餐食材进行处理
			// 1.去掉所有套餐区的菜品
			var i = 0;
			var arrLength = foodsArr.length;
			while(i<arrLength) {
				if(foodsArr[i]['ftype'] == 'colfood') {
					var delIndex = i;
					foodsArr.splice(delIndex, 1);
					arrLength = foodsArr.length;
				} else {
					i++;
				}
			}

			// 2.添加新套餐的菜品
			$('#menuWrap .order-num').each(function(){
				if(orderColName == $(this).parents(".colfoods").attr('colname') && 
					$(this).children('.fcheck').is(':checked')) {
					// 对checkbox进行勾选操作
					var    fid = $(this).attr("fid");
					var  ftype = $(this).data("ftype");
					var  fname = $(this).attr("name");
					var sortid = parseInt($(this).data("sort"));
					var price = parseInt($(this).data("price"));	// 单价
					var curNum = 1;
					var newItem = {'fid':fid, 'sort':sortid, 'ftype':ftype, 'num':curNum, 'fname':fname, 'price':price};
					foodsArr.push(newItem);

				}
			});
			
			for(var i=0;i<foodsArr.length;i++) {
				//console.log(i + '-' + foodsArr[i]['fname']);
			}
			
			var foodsStatis = getFoodsAllStatistics();
			var allNumTotal = foodsStatis['allNumCount'];
			var disNumber = foodsStatis['allNumCount'];
			var colAndOpMoneyCount = parseInt(foodsStatis['colAndOpMoneyCount'],10);
			var plusMoneyCount = parseInt(foodsStatis['plusMoneyCount'], 10);
			
			// 记录前一次选择时套餐的总价
			isEqualColMoneyTotal = colAndOpMoneyCount;
			
			// 对底部是否显示进行判断
			var extraPrice = $("#extraPrice");
			var curColMoney = 0;
			for(var i=0; i<colPriceList.length;i++) {
				if(colPriceList[i]['colname'] == orderColName) {
					curColMoney = colPriceList[i]['money'];
				}
			}
			
			// 这边初始化值存在
			if(parseInt(colAndOpMoneyCount) <= colMoneyTotal) {
				if(plusMoneyCount > 0) {
					extraPrice.parent().css("display", "block");
					var dpPrice = plusMoneyCount;
					extraPrice.text(dpPrice);
				} else {
					extraPrice.parent().css("display", "none");
				}
			} else if(parseInt(colAndOpMoneyCount) > curColMoney) {
				extraPrice.parent().css("display", "block");
				var dpPrice = parseInt(colAndOpMoneyCount) + plusMoneyCount - colMoneyTotal;
				extraPrice.text(dpPrice);
			}
			
			var _condition = $('#sendCondition');
			console.log("total = " + foodsStatis['colAndOpMoneyCount']);
			// 如果套餐+备选少于套餐金额，进行提示，隐藏“提交订单”按钮
			if(foodsStatis['colAndOpMoneyCount'] >= colMoneyTotal) {
				_condition.parent().hide().next().show();
			} else {
				_condition.text('套餐未选满');
				_condition.parent().show().next().hide();
			}
			
			// 修改底部菜样数量
			$("#cartNum").text(foodsArr.length);
		}
	});
	
	$(".share_bg").click(function() {
		$(this).hide() ;
	}) ;

});
function onClickHander1(ele) {
	if(ele.checked){
		// selected
		$(ele).val(1);
    }else{
        // unselected 
        $(ele).val(0);
    }
}

function submitCheck() {
	var fSt = getFoodsAllStatistics();
	var colopMoneyCount = fSt['colAndOpMoneyCount'];
	if(colopMoneyCount < colMoneyTotal) {
		alert("请您选满套餐, 再提交订单^_^");
		return false;
	}
	$(".colfoods[colname!='"+orderColName+"']").remove();
	document.cart_form.submit();
}

</script>
<script src="__PUBLIC__/js/layer.js?2.x"></script>
<link href="__PUBLIC__/js/need/layer.css?2.0" type="text/css" rel="styleSheet" id="layermcss">

<script type="text/javascript" src="__PUBLIC__/js/msgalert.js?2.0"></script>
<div class="window" id="windowcenter">
	<div id="title" class="title mu-color" style="background-image: url('__PUBLIC__/images/msg-header.png');">点菜提醒<span class="close" id="alertclose"></span></div>
	<div class="content">
		<div id="txt"></div>
		<input type="button" value="开始点菜" id="windowclosebutton" name="开始点菜" class="txtbtn">
		<if condition="$orderid eq 0">
		<input type="button" value="取消当期" id="cancelorder" name="取消当期" class="txtbtn">
		</if>
	</div>
</div>
<if condition="C('showSysMsg') eq 1">
<div class="share_bg" style="display: block;">
	<img src="__PUBLIC__/images/gaiqi.png" style="width:100%">
</div>
</if>
</body>
<!--[$shareScript]-->
</html>